package com.csti.delio.pagos.client.pagosueldos;

import java.util.Date;


import com.csti.delio.main.client.idioma.DelioConstants;
import com.csti.delio.main.client.util.ComboboxFieldBinding;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.binding.FieldBinding;
import com.extjs.gxt.ui.client.binding.FormBinding;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.google.gwt.core.client.GWT;

public class PanelNuevoPago extends FormPanel {

	private DelioConstants k = GWT.create(DelioConstants.class);
	private Button btnRegisrar;
	private SimpleComboBox cmbFormapago;
	private FormBinding formBindings;
	private NumberField txtSueldo;
	private NumberField txtAporte;
	private NumberField txtExtras;
	private NumberField txtCompensacion;
	private NumberField txtDescuento;
	private NumberField txtAdelanto;
	private NumberField txtNeto;
	private DateField fecha;

	public PanelNuevoPago() {
		super();
		setHeading(k.pagosueldo());
		setLabelAlign(LabelAlign.TOP);

		formBindings = new FormBinding(this);

		btnRegisrar = new Button(k.registrar());

		txtSueldo = new NumberField();
		txtSueldo.setFieldLabel(k.sueldo());
		txtSueldo.setPropertyEditorType(Double.class);

		txtAporte = new NumberField();
		txtAporte.setFieldLabel(k.aporte());
		txtAporte.setPropertyEditorType(Double.class);

		txtExtras = new NumberField();
		txtExtras.setFieldLabel(k.extras());
		txtExtras.setPropertyEditorType(Double.class);

		txtCompensacion = new NumberField();
		txtCompensacion.setFieldLabel(k.compensacion());
		txtCompensacion.setPropertyEditorType(Double.class);

		txtDescuento = new NumberField();
		txtDescuento.setFieldLabel(k.descuento());
		txtDescuento.setPropertyEditorType(Double.class);

		fecha = new DateField();
		fecha.setFieldLabel(k.fechapago());
		fecha.setValue(new Date());

		cmbFormapago = new SimpleComboBox();
		cmbFormapago.setFieldLabel(k.formapago());
		cmbFormapago.setAllowBlank(false);

		txtAdelanto = new NumberField();
		txtAdelanto.setFieldLabel(k.adelanto());
		txtAdelanto.setPropertyEditorType(Double.class);

		txtNeto = new NumberField();
		txtNeto.setFieldLabel(k.neto());
		txtNeto.setPropertyEditorType(Double.class);

		add(cmbFormapago, new FormData("95%"));
		add(fecha, new FormData("95%"));
		add(txtAporte, new FormData("95%"));
		add(txtDescuento, new FormData("95%"));
		add(txtAdelanto, new FormData("95%"));
		add(txtCompensacion, new FormData("95%"));
		add(txtExtras, new FormData("95%"));
		add(txtNeto, new FormData("95%"));

		addButton(btnRegisrar);
		setButtonAlign(HorizontalAlignment.CENTER);

	}

	public void setStore(ListStore<BeanModel> store) {

		formBindings.addFieldBinding(new FieldBinding(txtAporte, "aporte"));
		formBindings.addFieldBinding(new FieldBinding(txtAdelanto, "adelanto"));
		formBindings.addFieldBinding(new FieldBinding(txtDescuento, "descuento"));
		formBindings.addFieldBinding(new FieldBinding(txtCompensacion,"compensacion"));
		formBindings.addFieldBinding(new FieldBinding(txtExtras, "estras"));
		formBindings.addFieldBinding(new FieldBinding(txtNeto, "neto"));
		formBindings.addFieldBinding(new FieldBinding(fecha, "fecha"));
		formBindings.addFieldBinding(new ComboboxFieldBinding(cmbFormapago,"formapago"));
		formBindings.addFieldBinding(new FieldBinding(txtSueldo, "sueldo"));
		formBindings.setStore(store);
	}

	@Override
	public void reset() {

		
		txtAporte.clear();
		txtAdelanto.clear();
		txtDescuento.clear();
		txtCompensacion.clear();
		txtExtras.clear();
		txtNeto.clear();
		cmbFormapago.clearSelections();
		fecha.clear();

		// EmpleadoPanel.grid.getSelectionModel().deselectAll();
		unbind();

	}

	public void bind(BeanModel selectedModel) {
		formBindings.bind(selectedModel);
	

	}

	public void unbind() {
		formBindings.unbind();
	
	}
}
